import React from 'react'
import { createBrowserRouter, redirect } from 'react-router-dom'

const Login = React.lazy(() => import('@/pages/login'));
const Layout = React.lazy(() => import('@/layout'));

export const router = createBrowserRouter([
  {
    path: '/',
    element: <Layout />,
    loader: () => {
      console.log('loader')
      // 判断登录是否过期
      const token = true;
      if (!token) {
        return redirect('/login')
      }
      return {
        username: 'admin'
      }
    }
  },
  {
    path: 'login',
    element: <Login />
  }
]);
